Cgroups : Configure Rules
2017/08/30 |
It's possible to apply rules of tasks in Control Groups automatically to set configuration on conf file.
|
|
[1] | Start Cgred service that applys tasks to Control Groups by setting file. |
[root@dlp ~]# systemctl start cgred [root@dlp ~]# systemctl enable cgred
|
[2] | This is an example to set rules. |
# create a Control Group [root@dlp ~]# cgcreate -g cpu:/cpu_quota-70 [root@dlp ~]# cgset -r cpu.cfs_quota_us=70000 cpu_quota-70 [root@dlp ~]# cgget -g cpu /cpu_quota-70 /cpu_quota-70: cpu.rt_period_us: 1000000 cpu.rt_runtime_us: 0 cpu.stat: nr_periods 0 nr_throttled 0 throttled_time 0 cpu.cfs_period_us: 100000 cpu.cfs_quota_us: 70000 cpu.shares: 1024
[root@dlp ~]#
vi /etc/cgrules.conf # add to the end line # [user] [subsystem] [control group] cent cpu /cpu_quota-70 # for specific comman/script, set [user:command] # possible to use wild card (* = all) # below means [test.sh] by all users set in [cpu_quota-70] group *:test.sh cpu /cpu_quota-70 # for specifying group, set [@group] @cent cpu /cpu_quota-70
[root@dlp ~]# systemctl restart cgred
# make sure with [cent] user # run test job [cent@dlp ~]$ yes > /dev/null & [1] 1353 # CPU#0 is limited for 70% by [cpu_quota-70] [cent@dlp ~]$ mpstat -P ALL 1 1 | grep ^Average Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle Average: all 34.67 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 65.33 Average: 0 69.70 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 30.30 Average: 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 |